<template>
  <div>
    <!-- 搜索框 -->
    <TopFilter ref="form" :list="form" :cols="3" :labelWidth="'85'" @filterChange="changeHandle" />
    <FilterTable
      ref="orderTable"
      :columns="columnsList"
      columnsRef="partPartOutboundInternalReceiveSearchInternalReceivePage"
      :fetchapi="getTableData"
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columnsList = columns)"
      :height="'200'"
      selectionType="single"
      :onRowSelectChange="selectRow"
    ></FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog(1)">取 消</el-button>
      <el-button v-loading="loading" :disabled="isSave" type="primary" @click="closeDialog(2)">确 认</el-button>
    </div>
  </div>
</template>

<script>
import { getOrderData, getOrgByOrgType, getLingLiaoRenSelect } from '@/api/part/partOutbound/internalReceive/index';
import { dictionary } from '@/utils/dictMixin';
import { arrayObjDeWeight } from '@/utils/index';
// 查询与员工用户有关的信息
import { searchRoleByCode } from '@/api/common/empSelect/index';
import dictCode from '@/utils/dictCode';
import { getDealerUser } from '@/api/part/partInventory/partInventory/index.js';

export default {
  name: 'searchInOrderPage',
  mixins: [dictionary],
  props: ['orderNo', 'salerList', 'ptype'],
  data() {
    return {
      isSave: false,
      loading: false,
      form: this.createTopFilterList(),
      columnsList: this.createTableColumns(),
      getTableData: getOrderData,
      selectRowData: {},
      fetchParams: { xhrAbort: true },
      department: []
    };
  },
  created() {
    this.getlist();
  },
  mounted() {
    this.getOrgByOrgType();
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '领用单号',
          fieldName: 'receiptNo',
          initialValue: this.orderNo
        },
        {
          type: 'RANGE_DATE',
          label: '领用日期',
          fieldName: 'innerStr|innerEnd'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '领用单号', dataIndex: 'RECEIPT_NO', sorter: true, filter: true, filterType: 'input' },
        { title: '领用人', dataIndex: 'EMPLOYEE_NO', editable: false, editType: 'select', editItems: [], editRequired: 'false', disabled: true, filter: true, filterType: 'checkbox', filterItems: [] },
        {
          title: '部门',
          dataIndex: 'ORG_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        { title: '领用日期', dataIndex: 'RECEIPT_DATE', dateFormat: 'yyyy-MM-dd', sorter: true, filter: true, filterType: 'date-range' },
        {
          title: '锁定人',
          dataIndex: 'LOCK_USER',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '出库状态',
          dataIndex: 'STATUS',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems:[{ text: '已出库', value: 1 },
            { text: '未出库', value: 0 },
            { text: '部分出库', value: 2 }],
          dictItems: [
            { text: '已出库', value: 1 },
            { text: '未出库', value: 0 },
            { text: '部分出库', value: 2 }
          ]
        },
        // {
        //   title: '审核人',
        //   dataIndex: 'AUDITOR',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   render: props => {
        //     return <span>{this.salerList[props.row.AUDITOR]}</span>;
        //   }
        // },
        // { title: '审核日期', dataIndex: 'AUDIT_DATE', sorter: true, filter: true, filterType: 'input', dateFormat: 'yyyy-MM-dd' },
        { title: '备注', dataIndex: 'REMARK', sorter: true, filter: true, filterType: 'input' }
      ];
    },
    async getOrgByOrgType() {
      const res = await getOrgByOrgType({ orgType: 15061004 });
      // if (res.resultCode == 200) {
      this.department = res.data;
      // }
    },
    changeHandle(val) {
      console.log(val, 'val');
      let obj = _.cloneDeep(val);
      if (obj.innerStr) {
        obj.innerStr = obj.innerStr.substr(0, 10);
      }
      if (obj.innerEnd) {
        obj.innerEnd = obj.innerEnd.substr(0, 10);
      }
      console.log(obj, 'obj');
      this.fetchParams = Object.assign({}, obj, { ptype: this.ptype });
    },
    FormPanelSeacher() {
      this.$refs.formPanel.SUBMIT_FORM();
    },
    formchangeFun(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val, { ptype: this.ptype }, { xhrAbort: false });
    },
    selectRow(row) {
      console.log(row);
      this.selectRowData = row;
    },
    confirmFun() {},
    // 获取数据字典数据
    async getlist() {
      // 获取领料人
      const res = await getDealerUser();
      let salerResult = arrayObjDeWeight(res.data, 'userId');
      this.columnsList.find(x => x.dataIndex === 'EMPLOYEE_NO').filterItems = this.columnsList.find(x => x.dataIndex === 'EMPLOYEE_NO').editItems = salerResult.map(x => ({
        value: x.userId,
        text: x.employeeName
      }));
    },
    closeDialog(param) {
      if (param == 1) {
        this.$emit('close', false, param);
      } else {
        if (!this.selectRowData.length) {
          this.$notify({ title: '警告信息', message: '请选择需要添加的记录！', type: 'warning' });
          return;
        }
        this.$emit('showOrder', this.selectRowData);
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
